package net.oschina.app.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.FriendBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by wei03 on 2017/1/14.
 */

public class MeFollowRvAdapter extends BaseAdapter {

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(CommonUtils.getContext()).inflate(R.layout.item_follow, parent, false);
        MeFollowHolder meFollowHolder = new MeFollowHolder(itemView);
        return meFollowHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        FriendBean friendBean = (FriendBean) mDatas.get(position);
        MeFollowHolder meFollowHolder = (MeFollowHolder) holder;
        Glide.with(CommonUtils.getContext()).load(friendBean.getPortrait()).into(meFollowHolder.mIvUser);
        meFollowHolder.mTvName.setText(friendBean.getName());
        meFollowHolder.mIvSex.setImageResource(friendBean.getGender() == 1 ?
                R.drawable.userinfo_icon_male:R.drawable.userinfo_icon_female);
        meFollowHolder.mTvFrom.setText(friendBean.getFrom());
        meFollowHolder.mTvDesc.setText(friendBean.getExpertise());
    }

    class MeFollowHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_user)
        CircleImageView mIvUser;
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.iv_sex)
        ImageView mIvSex;
        @BindView(R.id.tv_from)
        TextView mTvFrom;
        @BindView(R.id.tv_desc)
        TextView mTvDesc;

        MeFollowHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
